/*
 * CoverFlowNode.fx
 *
 * Created on Apr 19, 2010, 2:54:45 PM
 */

package fxgreader.components;
import javafx.scene.CustomNode;
import javafx.scene.Node;
import javafx.animation.Interpolator;
import javafx.animation.Timeline;
import javafx.scene.input.MouseEvent;
import javafx.scene.Cursor;
import javafx.scene.Group;
import javafx.scene.effect.PerspectiveTransform;
import javafx.scene.paint.Color;
import javafx.scene.effect.Reflection;
import javafx.scene.shape.Rectangle;

/**
 * @author perkintang
 */

public class CoverFlowNode extends CustomNode {
public var objs : Object[];
public var indexOfpositionerArray : Integer;
public var ori_width:Number;
public var ori_height:Number;
public var offsetX:Number on replace{
};
public var offsetY:Number;
public var scalrate: Number = 1;
public var scalrate_to : Number =1;
public var dw:Number;
public var duh:Number;
public var dlh:Number;
public var dw_to : Number =  dw;
public var duh_to : Number =  duh;
public var dlh_to : Number =  dlh;
public var ori_height_to : Number =  ori_height;
public var ori_width_to : Number =  ori_width;
public var offsetx_to : Number =  offsetX;
public var offsety_to : Number =  offsetY;
override public var blocksMouse = true;
override public var focusTraversable = false;
public var afterMove : function(index : Integer,max : Number,node : CoverFlowNode);
public var onclick : function(index : Integer);
override public var onMouseClicked = function(event :MouseEvent):Void{
    onclick(indexOfpositionerArray);
};
protected var anim : Timeline;
public var fraction : Number = 0.3;
public function move(){
    anim = Timeline {
    repeatCount: 1
    keyFrames : [
    at(0.5s) {
        dw => dw_to tween Interpolator.EASEBOTH;
        duh => duh_to tween Interpolator.EASEBOTH;
        dlh => dlh_to tween Interpolator.EASEBOTH;
        ori_height => ori_height_to tween Interpolator.EASEBOTH;
        ori_width => ori_width_to tween Interpolator.EASEBOTH;
        offsetX => offsetx_to tween Interpolator.EASEBOTH;
        offsetY => offsety_to tween Interpolator.EASEBOTH;
        scalrate => scalrate_to tween Interpolator.EASEBOTH;
    }
    ]
    };
    anim.playFromStart();
};
public function quickMove(hid : Boolean){
        duh = duh_to ;
        dlh = dlh_to ;
        ori_height = ori_height_to ;
        ori_width = ori_width_to ;
        offsetX = offsetx_to ;
        offsetY = offsety_to ;
        scalrate = scalrate_to ;
        if(hid){
            hidden();
        }

}
public function hidden(){
    group.content = [];
}
protected var group : Group;
public var background = Rectangle {
                        effect: Reflection { fraction: bind fraction }
                        stroke : Color.WHITE
                        width:  bind ori_width  height:  bind ori_height
                        arcWidth: 20  arcHeight: 20
                 };
override function create():Node {
            cursor = Cursor.HAND;
            group = Group {
                translateX: bind offsetX
                translateY: bind offsetY
                effect : PerspectiveTransform {
                       ulx: bind dw
                       uly: bind -duh
                       urx: bind ori_width - dw
                       ury: bind duh
                       lrx: bind ori_width - dw
                       lry: bind ori_height - dlh + ori_height*fraction
                       llx: bind dw
                       lly: bind ori_height + dlh + ori_height*fraction
                }
                onMouseEntered : function(event : MouseEvent):Void{
                       background.stroke = Color.BLUE;
                }
                onMouseExited:function(event : MouseEvent):Void{
                       background.stroke = Color.WHITE;
                }
                content: [background]
}
}
public function load():Void{};
public function release(){};
}
